package oa.struts.action;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;

import oa.domain.system.User;
import oa.service.UserService;
import oa.struts.action.base.BaseAction;
import oa.util.OAUtils;

@Controller("modifyPasswordAction")
public class ModifyPasswordAction extends BaseAction<User>{

	@Resource(name="userService")
	private UserService userService;
	
	 //用于修改密码
    private String oldpass;  //原始密码
    private String newpassword;   //新密码
    private String passagain;  //再次输入的密码
	public String getOldpass() {
		return oldpass;
	}
	public void setOldpass(String oldpass) {
		this.oldpass = oldpass;
	}
	public String getNewpassword() {
		return newpassword;
	}
	public void setNewpassword(String newpassword) {
		this.newpassword = newpassword;
	}
	public String getPassagain() {
		return passagain;
	}
	public void setPassagain(String passagain) {
		this.passagain = passagain;
	}
    

	/**
	 * 修改密码
	 * @return
	 */
	public String modifyPasswordUI(){
		return "modifyPasswordUI";
	}
	
	public String modifyPassword(){
		User user = OAUtils.getUserFromSession();
		System.out.println("--------------");
		System.out.println(user.getPassword());
		if(oldpass.equals("") || newpassword.equals("") || passagain.equals(""))
		{	
			this.addActionMessage("密码不能为空");
			return "modifyPasswordUI";
		}
		else if(!oldpass.equals(user.getPassword()))
		{
			this.addActionMessage("原始密码输入错误");
			return "modifyPasswordUI";
		}
		else if(!newpassword.equals(passagain))
		{
			this.addActionMessage("用户名或者密码错误原始密码输入错误");
			return "modifyPasswordUI";
		}
		else
		{
			user.setPassword(newpassword);
			this.userService.updateUser(user);
			return "message";
		}
	}
	
}
